package com.wm.job;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Test {

    public static List<Job> list = new ArrayList<>();

    public static void showJobList()
    {
        System.out.println("排序前:");
        System.out.println("职位编号" + "\t"
                + "职位名称" + "\t"
                + "行业" + "\t"
                + "招聘人数" + "\t"
                + "发布时间");
        for(Job job:list)
        {
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println(job.getJobId() + "\t"
                    + job.getJobName() + "\t"
                    + job.getIndustry() + "\t"
                    + job.getNumber() + "\t" +
                    job.getPubDate().toLocaleString());
        }
        list.sort(new PubDateComparator());
        System.out.println("排序后");
        System.out.println("职位编号" + "\t"
                + "职位名称" + "\t"
                + "行业" + "\t"
                + "招聘人数" + "\t"
                + "发布时间");
        for(Job job:list)
        {
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println(job.getJobId() + "\t"
                    + job.getJobName() + "\t"
                    + job.getIndustry() + "\t"
                    + job.getNumber() + "\t" +
                    job.getPubDate().toLocaleString());
        }
    }

    public static void searchJobByName(String jobName)
    {
        System.out.println("职位编号" + "\t"
                + "职位名称" + "\t"
                + "行业" + "\t"
                + "招聘人数" + "\t"
                + "发布时间");
        for(Job job:list)
        {
            if(job.getJobName().indexOf(jobName) != -1)
            {
                SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                System.out.println(job.getJobId() + "\t"
                        + job.getJobName() + "\t"
                        + job.getIndustry() + "\t"
                        + job.getNumber() + "\t" +
                        format.format(job.getPubDate()));
            }
        }

    }
    public static Date convertToDate(String input) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.parse(input);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
    public static void main(String[] args) {
        list.add(new Job(1,"Web前端","计算机",3,convertToDate("2018-10-09")));
        list.add(new Job(2,"UI","计算机",6,convertToDate("2018-10-01")));
        list.add(new Job(3,"JAVA工程师","计算机",13,convertToDate("2018-7-31")));
        list.add(new Job(4,"数据库管理员","计算机",3,convertToDate("2018-10-11")));
        showJobList();
        Scanner in = new Scanner(System.in);
        System.out.println("请输入你要查找的职位名称:");
        String name = in.next();
        searchJobByName(name);

    }

}
